<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<#include "/common/resources.ftl"/>
<script type="text/javascript">
	$(function(){
	    
		window.m_datagrid = $('#m_datagrid').datagrid({
			url:'${ctx}/qfbao/preloanorder/list',
			onLoadSuccess:yixun.closeProgress,
			onBeforeLoad:yixun.progress,
			queryParams:$('#load_list_search').serializeObject(),
			loadMsg:null,
			singleSelect:true,
			fitColumns:true,
			rownumbers:true,
			pagination:true,
			border:'false',
			toolbar:'#m_toolbar'
		});
	
		//按条件查询用户
		window.searchData = function () {
			m_datagrid.datagrid('load',$('#load_list_search').serializeObject());
		}
		
		//删除
		window.openFpsh = function(id){
		      $("#pre_cus_id").val(id);
              $("#fpsh").window('open');
		}
		
		$('#fpsh').window('close');
		getCompany();
	});
	mShowButton = function (value,row,index){
		var btns = [];
		if(row.status=="1"){
		    btns.push('<button class="green_btn" onclick="javascript:openFpsh('+value+');void(0);">分配商户</button>');
		}
		return btns.join('');
	}
	
   statusName = function (value,row,index){
		var statusName="";
		if(value=="1"){
		   statusName="未分配";
		}else if(value=="2"){
		   statusName="已分配";
		}
		return statusName;
	}
	
	function fpsh(){
	    var pre_cus_id=$("#pre_cus_id").val();
	    var companyId=$("#companyId").combobox('getValue');
	    var productId=$("#productId").combobox('getValue');
	    if(pre_cus_id==""){
	       $.messager.alert('警告','ID错误');  
	       return;
	    }
	    
	    if(companyId==""){
	       $.messager.alert('警告','请选择商户');  
	       return;
	    }
	    
	    if(productId==""){
	       $.messager.alert('警告','请选择产品');  
	       return;
	    }
	    
	    $.ajax({
			url:"${ctx}/qfbao/preloanorder/fpMerchant",
			type: "POST",
			data:{
				id:pre_cus_id,
				companyId:companyId,
				productId:productId
			},
			dataType:"json",
			success:function(rs){
				if(rs.isSuccess=="T"){
				    $('#fpsh').window('close');
					m_datagrid.datagrid('load',$('#load_list_search').serializeObject());
				}else{
				    $.messager.alert('错误',rs.msg);  
				}
			}
		})
	   
	    
	}
	
	function getCompany(){
		$('#companyId').combobox({    
		    url:'${ctx}/jr/company/getList?companyType=2',    
		    valueField:'id',    
		    textField:'companyName',
		    onSelect:function(rec){
		    	queryProduct(rec.id);
		    }  
		});
	}
	
	function queryProduct(companyId){
	    $('#productId').combobox({
      		url:'${ctx}/qfbao/product/queryProductByCompanyId?companyId='+companyId,    
	  		valueField:'id',    
	  		textField:'name'
   		});
	}
</script>
</head>
<body style="background-color:white;">

<div id="m_toolbar" class="datagrid-toolbar" style="overflow: hidden;height: auto;margin: 15px 0px;background-color: white;border-bottom: none;" border="false">
  <form id="load_list_search" onsubmit="return false;">
  <div class="fm_sty" style="margin: 20px 0px 0px;">

   	<div class="ipt_line">
	    <span class="ipt_title">姓名</span>
		<input type="text" name="applicant" class="ipt_226" />
	</div>
	
   	<div class="ipt_line">
	    <span class="ipt_title">手机号码</span>
		<input type="text" name="phone" class="ipt_226" />
	</div>

	<div class="ipt_line_long">
        <button class="red_100" onclick="searchData()">查询</button>
	</div>    
  </div>
  </form>
</div>

<!-- 查找结果 -->
<table style="margin:0px 20px;" id="m_datagrid">
	<thead>
		<tr>
			<th field="applicant" width="60" height="40" >姓名</th>
			<th field="phone" width="60" height="40" >手机号码</th>
			<th field="applyAmount" width="60" height="40" >贷款金额(万)</th>
			<th data-options="field:'status',formatter:statusName" field="status" width="60" height="40" >状态</th>
			<th field="applyDate" width="80" height="40" >申请时间</th>
			
			<!--<th field="status" width="60" height="40" >1未分配 2已分配</th>
			<th field="companyId" width="60" height="40" >贷款公司ID</th>
			<th field="productId" width="60" height="40" >产品ID</th>-->
			<th data-options="field:'id',formatter:mShowButton,align:'center'" width="150">操作</th>
		</tr>
	</thead>
</table>

<div id="fpsh" class="easyui-dialog" title="分配商户" style="width:300px;height:200px;padding:10px 20px;"  data-options="iconCls:'icon-save',resizable:true,modal:true" >   
        	<div class="easyui-layout" fit="true">
			        <div region="center" border="false">
				   			<div class="fitem">
								<label>选择商户:</label>
								<select required="true" id="companyId" class="easyui-combobox" style="width:180px;">
									<option value=""></option>
								</select>
							</div>
							<div  class="fitem">
								<label>选择产品:</label>
								<select required="true" id="productId" class="easyui-combobox" style="width:180px;">
									<option value=""></option>
								</select> 
							</div>
					
		                    <input id="pre_cus_id"  type="hidden"/>
			
   			         </div>
   			         
   			         <div region="south" border="false" style="text-align:right;height:30px;line-height:30px;">
						<a href="#" class="easyui-linkbutton" iconCls="icon-ok" plain="true" onclick="fpsh();">保存</a>
						<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="javascript:$('#fpsh').window('close')">取消</a>
					</div>
   			</div>
   		

      
</div>

</body>
</html>
